home *** CD-ROM | disk | FTP | other *** search
Text File | 2000-09-28 | 11.9 KB | 619 lines | [TEXT/LTLK] |
- %
- % File: StyleProcs.ps
- %
- % This file contains the procedures used for Skia styles.
- % This includes procedures and structures related to the augmented graphics state.
- %
- % Version: Technology: Quickdraw GX 1.1.x.
- %
- % Copyright: © 1991-7 by Apple Computer, Inc., all rights reserved.
- %
- %
- % File contains the following procedures:
- % SetPat
- % CurrPat
- % SetGridFit
- % CurrGridFit
- % SetBold
- % CurrBold
- % HasBold
- % SetDash
- % CurrDash
- % SetRightIsOut
- % CurrRightIsOut
- % SetFrame
- % CurrFrame
- % SetStyle
- % MakeStyleDict
- % NewAugState
- % AugGsave
- % AugGrestore
- % FullGsave
- % FullGrestore
- % CurrColorSet
- % SetColorSet
- % CurrOrMode
- % SetOrMode
- % SetBaseFont
- % GetBaseFont
-
-
-
- %<FF>
- % The Augmented Graphics State dictionary, define the inital state:
- % Has 2 entries in level-2, 4 entries in level-1
- % Procedure NewAugGstate: Creates a new augmented graphics state dictionary, containing
- % Default values. (no-bold, no pattern, no grid fitting)
- %
- % - NewAugGstate dict
- %
- % dict: The new Augmented graphics state dictionary.
- %
- /NewAugGstate {
-
- 11 dict dup begin
-
- /xBold 0 def
- /yBold 0 def
- /dash null def
- /rightIsOut false def
- /frameType 0 def
- /FontMapping [1 0 0 1 0 0] def % The matrix that was applied to the current font.
- /ColorSet null def % Default color set space is null.
- /orMode 0 def % or-mode for 1 bit bitmaps?
- /baseFont null def % base font dictionary in augmented state.
- /pattern null def % pattern dictionary.
- /gridFit false def
-
- end
-
- } Bdef
-
- /AugGstate NewAugGstate def % Create an augmented graphics state in the main dictionary.
-
- %
- %<FF>
- %
- % Augmented graphics state save and restore operators and data structures:
- %
- /AugGsaveStack 31 array def % 31 entries, just like normal gsave.
-
- % Make 31 dictionaries
- 0 1 30 {AugGsaveStack exch NewAugGstate put} for
-
- /AugGsaveSP 0 def % Stack pointer for gsave stack.
-
- %
- % Procedure AugGsave:
- %
- % This procedure saves a copy of the current augmented graphics state on the stack.
- %
- /AugGsave {
-
- AugGsaveStack AugGsaveSP get % Copy the current one into the top of the stack.
- AugGstate
- CopyDict
-
- /AugGsaveSP Inc % Move the stack pointer
-
- } Bdef
-
- %
- % Procedure AugGrestore:
- %
- % This procedure restores the augmented graphics state from the stack.
- % If you call this with no AugGsaves on the stack, it screws up the Augmented Gstate dict.
- /AugGrestore {
-
- /AugGsaveSP Dec
- AugGsaveSP 0 lt {/AugGsave 0 store} if
-
- AugGstate
- AugGsaveStack AugGsaveSP get
- CopyDict % Copy the one off the stack into current one.
-
- } Bdef
-
- %
- % These two do a full gsave and grestore (Both mine and PostScript's)
- % However, perserve the current font across grestores to minimize the
- % need to do the oh, so expensive makefont/setfont operation.
- %
- /FullGsave {gsave AugGsave} Bdef
- /FullGrestore {AugGrestore currentfont grestore setfont} Bdef
-
-
- %
- % QD2Grestore: A grestore that maintains all of the style attributes that
- % PostScript would otherwise restore, pretty much everything but color which
- % The Imaging Engine maintains in a nested state.
- %
- /QD2Grestore {
-
- currentlinewidth
- currentlinecap
- currentlinejoin
- currentmiterlimit
- CurrGridFit
- currentfont
- currentdash
-
- grestore
-
- CurrPat null ne {
- SynchPatMatrix
- } if
-
- setdash
- setfont
- SetGridFit
- setmiterlimit
- setlinejoin
- setlinecap
- setlinewidth
-
- } Bdef
-
-
-
- %<FF>
- %
- % Augmented graphics state operators:
- %
-
- %
- % SetColorSet: Sets the current color set.
- % setDict CurrColorSet -
- %
- % setDict: An color set dictionary.
- %
- /SetColorSet {
-
- AugGstate /ColorSet 3 -1 roll put
-
- } Bdef
-
- %
- %
- % CurrColorSet: Get the current background color object
- % CurrColorSet setDict
- %
- % setDict: An indexed color space dictionary.
- %
- /CurrColorSet {
-
- AugGstate /ColorSet get
-
- } Bdef
-
-
- %
- % SetBold: Sets the bolding in the augmented graphics state.
- % x y SetBold -
- %
- % x,y: The x and y boldness values.
- %
- /SetBold {
-
- AugGstate /yBold 3 -1 roll put
- AugGstate /xBold 3 -1 roll put
-
- } Bdef
-
- %
- % CurrBold: Returns the current boldness from the augmented graphics state.
- %
- % - CurrBold xBold yBold
- %
- % xBold: x boldness value.
- % yBold: y boldness value.
-
- /CurrBold {
-
- AugGstate /xBold get
- AugGstate /yBold get
-
- } Bdef
-
- %
- % HasBold: A shortcut just to see if the current graphics state has boldness in it.
- %
- % - HasBold bool
- %
- % bool: true if the style contains non-zero boldness
- %
- /HasBold {
-
- CurrBold % xBold yBold
- 0 ne % xBold bool
- exch 0 ne % bool bool
- or % bool: if either xBold or yBold was non-zero.
-
- } Bdef
-
- %
- % SetGridFit: Sets the grid fitting in the graphics state.
- % boolean SetGridFit -
- %
- % boolean: Grid fitting on or off.
- %
- languagelevel 2 lt {
-
- /SetGridFit {
-
- AugGstate /gridFit 3 -1 roll put
-
- } Bdef
-
- /CurrGridFit {
-
- AugGstate /gridFit get
-
- } Bdef
-
- } {
-
- /SetGridFit /setstrokeadjust load def
- /CurrGridFit /currentstrokeadjust load def
-
- } ifelse
-
-
-
- %
- % SetPat: Sets the pattern dictionary in the augmented graphics state.
- % patternDict SetPat -
- %
- % patternDict: A valid pattern dictionary.
- %
-
- /SetPat {
-
- AugGstate /pattern 3 -1 roll put
-
- } Bdef
-
- %
- % CurrPat: Sets the pattern dictionary in the augmented graphics state.
- % CurrPat dict -
- %
- % dict: the current pattern dictionary.
- %
- /CurrPat { % Return the current pattern dictionary on the stack.
-
- AugGstate /pattern get
-
- } Bdef
-
-
-
- %<FF>
- %
- % SetDash: Sets the dashing in the augmented graphics state.
- % dashDict SetDash -
- %
- % dashDict: A valid dashing dictionary.
- % or
- % array phase SetDash - (Just like setdash operator) Data is from synonym
- %
- % If the data is from a synonym, put a null in the
- % Augmented graphics state for the dash dictionary
- % because QD2Fill checks this to decide whether or not to
- % do a DashStroke for Skia dashing or a normal stroke.
- % If the dash is from a synonym, then a normal stroke does the correct thing.
- %
- /SetDash {
-
- dup null eq { % If the dash is null, clear PostScript graphics state
-
- [] 0 setdash % Make sure there is no dash from a synonym
-
- } { % Else
-
- dup type /dicttype ne { % If the first parameter wasn't a dictionary, data must be from synonym
-
- setdash % Pass the synonym data to the setdash operator
- null % put a null on the stack to stick in Augmented graphics state
-
- } { % Else
-
- [] 0 setdash % clear PostScript dash, information is in our dictionary.
-
- } ifelse
-
- } ifelse
-
- AugGstate /dash 3 -1 roll put % Put dash dictionary into augmented graphics state.
-
- } Bdef
-
-
- %
- % CurrDash: return the current dashing dictionary.
- %
- /CurrDash {
-
- AugGstate /dash get
-
- } Bdef
-
- %<FF>
- %
- % SetFrame: Sets the frame type in the augmented graphics state.
- % frameType SetFrame -
- %
- % frameType: 0 for center, 1 for inside, -1 for outside
- %
- /SetFrame {
-
- AugGstate /frameType 3 -1 roll put
-
- } Bdef
-
-
- %
- % CurrFrame: return the current dashing dictionary.
- %
- /CurrFrame {
-
- AugGstate /frameType get
-
- } Bdef
-
- %
- % SetRightIsOut: Sets the rightIsOut attribute in the augmented graphics state.
- % bool SetRightIsOut -
- %
- % bool: value of bit from Skia style.
- %
- /SetRightIsOut {
-
- AugGstate /rightIsOut 3 -1 roll put
-
- } Bdef
-
-
- %
- % CurrRightIsOut: return the value of rightIsOut
- %
- /CurrRightIsOut {
-
- AugGstate /rightIsOut get
-
- } Bdef
-
-
- %
- % SetOrMode: Sets the or mode attribute in the augmented graphics state.
- % int SetOrMode -
- %
- % int: 0 means copy else 1 of the 4 ormodes. (0: copy 1: SrcOr, 2: SrcBic: 3: NotSrcOr, 4: NotSrcBic)
- %
- /SetOrMode {
-
- AugGstate /orMode 3 -1 roll put
-
- } Bdef
-
-
- %
- % CurrOrMode: return the value of orMode
- %
- /CurrOrMode {
-
- AugGstate /orMode get
-
- } Bdef
-
-
- %
- %
- % Routines for getting imagemask colors and sense based on the or mode value.
- %
- %
- % ImageMaskSense:
- %
- % returns boolean to pass to imagemask (paint 1 or 0 bits ) based on ormode.
- %
- /ImageMaskSenseArray [true true true false false] def
- /ImageMaskSense {
-
- ImageMaskSenseArray CurrOrMode get
-
- } Bdef
-
- %
- % ImageMaskColor: Returns index of color in current color set to paint image mask with.
- %
- /ImageMaskColorArray [1 1 0 1 0] def
- /ImageMaskColor {
-
- ImageMaskColorArray CurrOrMode get
-
- } Bdef
-
-
- %
- % SetBaseFont: Sets the base font in the augmented graphics state.
- % dict SetBaseFont -
- %
- % dict: a font dictionary. Usually of 1pt font.
- %
- /SetBaseFont {
-
- AugGstate /baseFont 3 -1 roll put
-
- } Bdef
-
-
- %
- % CurrBaseFont: Gets the current base font from the augmented graphics state.
- % CurrBaseFont dict
- %
- % dict: The current base font dictionary.
- %
- /CurrBaseFont {
-
- AugGstate /baseFont get
-
- } Bdef
-
- %<FF>
- %
- % The MakeStyleDict procedure:
- % Procedure makes a dictionary representing the Skia style.
- % Obviously, PostScriptable style attributes only, as described in ERS.
- %
- % patternDict rightIsOut frameType dash pen cap join mitre gridFit textSize MakeStyleDict dict
- %
- % patternDict: null or a valid pattern dictionary.
- % rightIsOut: Boolean (rightIsOut bit from style attributes)
- % frameType: 0 = center, 1 = inside, -1 = outside
- % dash: null or a dashing array.
- % pen: The pen thickness.
- % cap: The line cap type.
- % join: The line join type.
- % mitre: The mitre limit.
- % gridFit: (boolean) grid fitting or not.
- % textSize: The text size from the style.
- % dict: The dictionary created, left on the stack.
- %
- /MakeStyleDict {
-
- 10 dict dup begin % Make the dictionary, leave copy on stack.
- 11 1 roll % Put duplicate dictionary behind parameters.
-
- /textSize Xdef
- /gridFit Xdef
- /mitre Xdef
- /join Xdef
- /cap Xdef
- /pen Xdef
- /dash Xdef
- /frameType Xdef
- /rightIsOut Xdef
- /pattern Xdef
-
- end
-
- } Bdef
-
- %
- % The nilStyleDict is the style to use in a text face layer that had a nil outlineStyle field.
- %
- /nilStyleDict 10 dict dup
- begin
- /textSize 1 def
- /gridFit false def
- /mitre 1000 def
- /join 0 def
- /cap 0 def
- /pen 0 def
- /dash null def
- /frameType 0 def
- /rightIsOut F def
- /pattern null def
-
- end
- def
-
-
- %<FF>
- %
- % The SetStyle procedure:
- % Procedure takes a Style Dictionary and applies its contents to the current graphics state.
- %
- % styleDict SetStyle -
- %
- % styleDict: A valid style dictionary.
- %
- /SetStyle {
-
- dup /dash get SetDash
-
- dup /pattern get SetPat
-
- dup /rightIsOut get SetRightIsOut
-
- dup /pen get setlinewidth
-
- dup /cap get setlinecap
-
- dup /join get setlinejoin
-
- dup /mitre get setmiterlimit
-
- dup /frameType get SetFrame
-
- /gridFit get SetGridFit
-
-
- } Bdef
-
-
-
-
-
-
-
-
- %<FF>
- %
- % SynchPatMatrix:
- %
- % In PostScript level-2, the pattern is bound to the matrix that was in the graphics
- % state at the time the makepattern was executed. In Skia, patterns map through whatever
- % the shape's transform is (unless portAllignPattern is set in the styleAttributes)
- %
- % In Level-1, we use this procedure to re-gridfit our vectors and mappings.
- %
- % Execution of this procedure makes sure the pattern is synchronized to the CTM and should
- % Be called whenever the CTM is modified. (MapCTM or any grestore type of operation)
- %
- languagelevel 1 gt {
-
- /SynchPatMatrix {
-
- CurrPat null ne { % If there is a pattern in augmented state.
-
- CurrPat dup
- /patTransform get makepattern % remake the pattern
- SetPat % put new one in augmented graphics state.
-
- } if
-
- } Bdef
-
-
- } { %% For level-1 just re-transform and re-grid the vectors.
-
- /SynchPatMatrix {
-
- CurrPat null ne {
-
- CurrPat begin
-
- /patTransform [ % Make the matrix by grid fitting parameters.
-
- ux uy Grid
- vx vy Grid
- px py Grid
-
- ] def
-
- /IpatTransform patTransform IpatTransform invertmatrix def
-
- % Reset the advance width vectors in the pattern font.
-
- patternFontDict /AdvanceVector get patTransform 0 get 0 exch put
- patternFontDict /AdvanceVector get patTransform 1 get 1 exch put
-
-
- end
-
- } if
-
- } def
-
- } ifelse % level-1 or level-2
-